#ifndef _COMMON_TOOLS_H_
#define _COMMON_TOOLS_H_

#include <string>
#include <vector>

#include <locale>
#include "hstring.hpp"

namespace common {

class tools {

public:
    template<typename T>
    static T slash() { 
#ifdef _WIN32    
        return '\\'; 
#else
        return '/';
#endif
    }

    template<typename T>
    static ydd::hstring<T> get_file_name(const ydd::hstring<T>& _full_path, bool _include_suffix) {
        std::vector<ydd::hstring<T>> l_list;
        _full_path.split(l_list, {'/', '\\'});
        if (l_list.empty()) {
            return ydd::hstring<T>();
        }
        ydd::hstring<T> l_name = l_list[l_list.size() - 1];
        if (!_include_suffix) {
            size_t l_index = l_name.rfind('.');
            if (-1 != l_index) {
                l_name = l_name.substr(0, l_index);
            }
        }
        return l_name;
    }
    template<typename T>
    static ydd::hstring<T> get_last(const ydd::hstring<T>& _value, const ydd::hstring<T>& _separate) {
        std::vector<ydd::hstring<T>> l_list;
        _value.split(l_list, _separate);
        if (l_list.empty()) {
            return ydd::hstring<T>();
        }
        return l_list[l_list.size() - 1];
    }
    template<typename T>
    static void add_slash(ydd::hstring<T>& _value) {
        if (_value.is_end_by(slash<T>(), true)) {
            return;
        }
        _value << slash<T>();
    }
};

}

#endif
